﻿<?php
// ------------------------------------------------------------------
// NEEDED STUBS FOR THIS EXAMPLE
// ------------------------------------------------------------------


// this will include all needed files to be able to build a Request
include_once($CONF["STUBS_FOLDER"]."Map24Routing/Map24Routing.php5");


// ------------------------------------------------------------------
// NEEDED PARAMETERS FOR THIS REQUEST
// ------------------------------------------------------------------


// the start address (coordinates)
$sLongitude = '520.97131347656';
$sLatitude 	= '3008.740234375';

// the destination address (coordinates)
$dLongitude = '799.04816';
$dLatitude 	= '3150.0925';

// definition of the Properties

// Specifies if ferries should be preferred or avoided on a scale between 1 (prefer ferries) and 5 (avoid ferries)
$proIdx=0;
$property[$proIdx]= new Property();
$property[$proIdx]->Key = "preff";
$property[$proIdx]->Value = "2";

// Specifies if motorways should be preferred or avoided on a scale between 1 (prefer motorways) and 5 (avoid motorways)
$proIdx++;
$property[$proIdx]= new Property();
$property[$proIdx]->Key = "prefa";
$property[$proIdx]->Value = "4";

// the language for the route description
$descriptionLanguage = "DE";		//EN


// ------------------------------------------------------------------
// BUILDING THE REQUEST
// ------------------------------------------------------------------


// definition of the request header with Map24ID and SessionID
$header = new RequestHeader();
$header->Map24ID  = $CONF['MAP24_ID'];
$header->ClientID = $CONF['SESSION_ID'];

// definition of the request body
$request = new CalculateRouteRequest();

// define the Start Address
$request->Start = new CoordinateAndAddress();
$request->Start->Coordinate = new Coordinate();
$request->Start->Coordinate->Longitude = $sLongitude;
$request->Start->Coordinate->Latitude = $sLatitude;

// define the Destination Address
$request->Destination = new CoordinateAndAddress();
$request->Destination->Coordinate = new Coordinate();
$request->Destination->Coordinate->Longitude = $dLongitude;
$request->Destination->Coordinate->Latitude = $dLatitude;

// define the Description Language
$request->DescriptionLanguage = $descriptionLanguage;

// define the Properties
$request->Properties = $property;

//define Speed Classificaton
$request->SpeedClassification = new RoutingRequestSpeedClassification();
$request->SpeedClassification->Motorway = $Speed['Motorway'];
$request->SpeedClassification->CityRoad = $Speed['CityRoad'];
$request->SpeedClassification->CountryRoad = $Speed['CountryRoad'];
$request->SpeedClassification->Ferry = $Speed['Ferry'];


// ------------------------------------------------------------------
// EXECUTE THE REQUEST
// ------------------------------------------------------------------


// in this object the SoapClient will be initiated and executed
$routing = new Map24Routing($CONF['MAPTP_SYSTEM'],$CONF['MAP24_ID'],$CONF['SESSION_ID']);
$response = $routing->calculateRoute($header,$request);


// ------------------------------------------------------------------
// OUTPUT THE RESULT
// ------------------------------------------------------------------


if( isset($response->Route) )
{
	foreach ($response->Route->Segments as $result)
	{
		$counter++;

		$resultString .= "<div style='border:1px solid black;margin:2px 0px;padding:5px;'>".$counter.". ";
		foreach ( $result->Descriptions as $description )
		{
			$resultString .= $description->Text."<br /><br />";
		}
		$resultString .= "</div>";
	}

	$RouteID=$response->Route->RouteID;
	// save the RouteID in a cookie (needed to show the route later)
	$t=date("U")+3600;
	SetCookie("RouteID",$RouteID,$t);
	//$resultString.="<p><a href='code_source.php?sid=" . $CONF['SESSION_ID'] . "&src=Map24MapletRemoteControl_showRoute.php5' target='codeframe'>MRC-Comand to show the Route</a>";
}
else
{
	$resultString= "No Answer from the Webserver";
}

?>